/*
 * Copyright (C) 2010-2011 Comcast Cable.  All Rights Reserved.
 */
package com.hercules.android.receiver.model.objects;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>This abstract class is a base class of all XRE Objects. It is a simple JavaBean (POJO) that provides getters and
 * setters for all private attributes and performs no argument validation in the setters.</p>
 *
 * <p><strong>Thread safety:</strong> This class is mutable and not thread safe.</p>
 *
 * @author saarixx, jmn
 * @version 1.0
 */
public abstract class XREObject {

    /**
     * <p>Constant for predefined object ID indicating empty resource or null object reference.</p>
     *
     * <p>Can be any value.</p>
     *
     * <p>Has getter and setter.</p>
     */
    public static final int ID_NULL = 0;

    /**
     * <p>Constant for predefined object ID indicating resource id of the application.</p>
     *
     * <p>Can be any value.</p>
     *
     * <p>Has getter and setter.</p>
     */
    public static final int ID_ROOT_APPLICATION = 1;

    /**
     * <p>Constant for predefined object ID indicating root view of the application.</p>
     *
     * <p>Can be any value.</p>
     *
     * <p>Has getter and setter.</p>
     */
    public static final int ID_ROOT_VIEW = 2;

    /**
     * <p>Constant for predefined object ID indicating first ID that can be used by the application.</p>
     *
     * <p>Can be any value.</p>
     *
     * <p>Has getter and setter.</p>
     */
    public static final int ID_CLIENT = 2048;

    /**
     * <p>The host assigned identifier for the object.</p>
     *
     * <p>Can be any value.</p>
     *
     * <p>Has getter and setter.</p>
     */
    private int id;

    /**
     * <p>The event handlers registered in this XREObject. Keys are event names.</p>
     *
     * <p>Can be any value, can contain any values.</p>
     *
     * <p>Has getter and setter.</p>
     */
    private Map<String, XREEventHandler> eventHandlers = new HashMap<String, XREEventHandler>();

    /**
     * <p>Creates new instance of {@link XREObject} class.</p>
     */
    protected XREObject() {
        // empty constructor
    }

    /**
     * <p>Retrieves the host assigned identifier for the object.</p>
     *
     * @return the host assigned identifier for the object
     */
    public int getId() {
        return id;
    }

    /**
     * <p>Sets the host assigned identifier for the object.</p>
     *
     * @param id the host assigned identifier for the object
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * <p>Retrieves the event handlers registered in this XREObject.</p>
     *
     * @return the event handlers registered in this XREObject
     */
    public Map<String, XREEventHandler> getEventHandlers() {
        return eventHandlers;
    }

    /**
     * <p>Sets the event handlers registered in this XREObject.</p>
     *
     * @param eventHandlers the event handlers registered in this XREObject
     */
    public void setEventHandlers(Map<String, XREEventHandler> eventHandlers) {
        this.eventHandlers = eventHandlers;
    }
}

